package hy.controller;


import hy.beans.AjaxResult;
import hy.beans.User;
import hy.dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserMapper dao;
    @GetMapping("/login")
    public AjaxResult login(User user, HttpSession session){
        System.out.println(user);
        User u=dao.selectUserByName(user.getName());
        System.out.println("正确用户："+u);
        AjaxResult rs=new AjaxResult();
        if(u!=null&&u.getPass().equals(user.getPass())){
            rs.setSuccess(true);
            session.setAttribute("user",u);
        }
        rs.setData(u);
        return rs;
    }
}